//
//  HQBaseRequestSDK.h
//  B2C_iPhone_V4
//
//  Created by JimBo on 15/7/21.
//  Copyright (c) 2015年 edu24ol. All rights reserved.
//

#import "YTKRequest.h"
#import "HQResponseStatus.h"



static const int TokenExpired = 40042;

@protocol HQBaseRequestSDKDelegate <NSObject>

@optional
///获取当前本地的最新token
- (NSString *)getCurrentToken_baseReqSDK;
- (uint64_t)getCurrentUserId_baseReqSdk;
@end


@interface HQBaseRequestSDK : YTKRequest

@property (nonatomic, strong) NSString* token;
@property (nonatomic, assign) NSInteger currentApiCacheSec;//缓存有效期

- (instancetype)initWithToken:(NSString *)token;

/**
 *  不使用缓存，不缓存数据
 */
- (void)startB2CRequestWithCompletionBlockWithSuccess:(void (^)(YTKBaseRequest *request))success
                                              failure:(void (^)(NSError *error))failure;

/**
 *  usingCache-YES: 如果有缓存，使用缓存，如果没有，从网络获取，并缓存到本地,缓存有效时间30分钟
 *  usingCache-NO:  不使用缓存，不缓存数据
 */
- (void)startB2CRequestUsingCache:(BOOL)usingCache
                          success:(void (^)(YTKBaseRequest *request))success
                          failure:(void (^)(NSError *error))failure;

/**
 *  无论有无本地缓存，都从网络获取并本地缓存,有效期为lifeSec
 */
- (void)updateB2CRequestCacheWithLife:(NSInteger)lifeSec
                              success:(void (^)(YTKBaseRequest *request))success
                              failure:(void (^)(NSError *error))failure;

///外部处理过期，生成最新的token
///子类重写
- (void)getTokenBlock:(void (^)(BOOL success,NSString * token))block;

//指定执行成功回调的状态码 默认0
- (NSSet *)successCodes;

- (NSDictionary *)addArgumentForCacheFileName;

- (NSArray *)filterKeyArrayForCacheFileName;
//默认不启动第一页缓存；子类重写
- (BOOL)isFirstPageRequest;
 ///可重写，返回为空的code
- (NSInteger)ErrorCode_HaveNoData;
@end

